(function(){
function _$(id){
    return document.getElementById(id);
}

Array.prototype.contains=function(item){
    var i;
    for(i=0;i<this.length;i++){
        if(this[i]==item)return true;
    }
    return false;
}

function _$find(tagName,className){
    var i,filtered=[],elems=document.getElementsByTagName(tagName);
    if(className){
        for(var i=0;i<elems.length;i++){
            if(elems[i].className.split(/\s+/).contains(className))
                filtered.push(elems[i]);
        }
        return filtered;
    }else{
        return elems;
    }
}

function loadjs(filename,fcallback){ 
    var fileref=document.createElement('script');//创建标签
    fileref.setAttribute("type","text/javascript");//定义属性type的值为text/javascript
    fileref.setAttribute("src", filename);//文件的地址
    var head=document.getElementsByTagName("head")[0];
    if (typeof fileref!="undefined"){ 
        fileref.onload = fileref.onreadystatechange = function(){
            if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") {
                if(typeof fcallback=='function')
                    fcallback();
                //head.removeChild();
            }
        };
        head.appendChild(fileref);
    }
}


function loadcss(filename){ 
    var fileref=document.createElement("link");
    fileref.setAttribute("rel", "stylesheet");
    fileref.setAttribute("type", "text/css");
    fileref.setAttribute("href", filename);
    if (typeof fileref!="undefined") 
        document.getElementsByTagName("head")[0].appendChild(fileref);
}

var hls=_$find("pre","brush:");
if(hls&&hls.length>0){
    loadcss("/js/syntaxHilighter/styles/shCore.css");
	loadcss("/js/syntaxHilighter/styles/shThemeDefault.css");

    loadjs('/js/syntaxHilighter/src/shCore.js',function(){
        loadjs('/js/syntaxHilighter/scripts/shBrushCSharp.js',function(){
            SyntaxHighlighter.config.clipboardSwf = '/js/syntaxHilighter/scripts/clipboard.swf';
            //SyntaxHighlighter.all();            
            SyntaxHighlighter.highlight();            
        });
    });
   /* 
    setTimeout(function(){
        if(SyntaxHighlighter && SyntaxHighlighter.all){
            SyntaxHighlighter.config.clipboardSwf = '/js/syntaxHilighter/scripts/clipboard.swf';
            SyntaxHighlighter.all();
        }else{
            setTimeout(arguments.callee,200);
        }
    },700);
    */
}

})();
